package com.yunxi.service.dubboService.impl.customer;

import com.github.pagehelper.PageInfo;
import com.yunxi.customer.pojo.SatCustomerIntentionHisVO;
import com.yunxi.customer.service.SatCustomerIntentionHisDubboService;
import com.yunxi.model.customer.SatCustomerIntentionHis;
import com.yunxi.service.localService.customer.SatCustomerIntentionHisService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.List;

/**
 * <p>
 * 客户意向历史 服务实现类
 * </p>
 *
 * @author
 * @since 2019-07-11
 */
public class SatCustomerIntentionHisDubboServiceImpl implements SatCustomerIntentionHisDubboService {

   @Autowired
   @Qualifier(value = "satCustomerIntentionHisServiceImpl")
   SatCustomerIntentionHisService satCustomerIntentionHisService;


   @Override
   public SatCustomerIntentionHisVO getById(String id) throws Exception {
      SatCustomerIntentionHis satCustomerIntentionHis = satCustomerIntentionHisService.getById(id);
      if(satCustomerIntentionHis != null){
         SatCustomerIntentionHisVO satCustomerIntentionHisVO = new SatCustomerIntentionHisVO();
         BeanUtils.copyProperties(satCustomerIntentionHis, satCustomerIntentionHisVO);
         return satCustomerIntentionHisVO;
      }
      else{
         throw new Exception("操作失败,无法根据id:"+id+"找到对应客户意向历史!");
      }
   }

   @Override
   public void saveOrUpdate(SatCustomerIntentionHisVO satCustomerIntentionHisVO) throws Exception {
      SatCustomerIntentionHis satCustomerIntentionHis = new SatCustomerIntentionHis();
      BeanUtils.copyProperties(satCustomerIntentionHisVO,satCustomerIntentionHis);
      satCustomerIntentionHisService.saveOrUpdate(satCustomerIntentionHis);
   }

   @Override
   public void removeById(String id) {
      satCustomerIntentionHisService.removeById(id);
   }

   @Override
   public PageInfo<SatCustomerIntentionHisVO> findPageByVO(SatCustomerIntentionHisVO satCustomerIntentionHisVO, Integer pageNum, Integer pageSize) throws Exception{
      return satCustomerIntentionHisService.pageByVo(satCustomerIntentionHisVO, pageNum, pageSize);
   }

   @Override
   public void removeByListVo(List<SatCustomerIntentionHisVO> list) throws Exception {
      satCustomerIntentionHisService.removeByListVo(list);
   }

   @Override
   public void del(List<String> list, String createBy) throws Exception {
      if(list != null && list.size() > 0){
         for (String id : list){
            SatCustomerIntentionHis byId = satCustomerIntentionHisService.getById(id);
            if(byId != null){
               byId.setIsDel(1);
               byId.setUpdateBy(createBy);
               satCustomerIntentionHisService.saveOrUpdate(byId);
            }
            else{
               throw new Exception("操作失败,无法根据id:"+id+"找到对应客户意向历史!");
            }
         }
      }
      else {
         throw new Exception("操作失败,list为空!");
      }
   }

}
